package com.app.business.service;

import com.app.business.model.OverAreaOneFloorSyPrice;
import com.app.business.model.SyKgInfo;
import com.app.system.jpa.JpaBaseDao;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * 商业对应购买及扩购面积
 * Created by szy on 2024/10/13
 */
@SuppressWarnings(value = "ALL")
@Service
@Transactional
public class SyKgInfoService extends JpaBaseDao<SyKgInfo,Integer> {
    @Autowired
    private ContractService contractService;

    /**
     * 删除某参数配置下所有的面积区间配置数据
     *
     * @param zsProjectId
     */
    public synchronized void deleteSyKgInfoByParameterId(Integer parameterId) {
        String sql = "delete from sy_kg_info where parameter_id = :parameterId";
        this.entityManager.createNativeQuery(sql).setParameter("parameterId", parameterId).executeUpdate();
    }

    /**
     * 通过参数配置得到下面所有的面积区间分配
     *
     * @return
     */
    public List<SyKgInfo> getSyKgInfoListByParameterId(Integer parameterId) {
        //查询语句
        StringBuffer hql = new StringBuffer("from SyKgInfo oap where oap.parameter.id =:parameterId order by oap.sortNum,oap.id");
        Map map = Maps.newHashMap();
        map.put("parameterId", parameterId);
        return this.findHql(hql.toString(), map);
    }
}
